#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int rotatedDigits(int n) {
        vector<int> dp(n + 1);
        for (int i = 1; i <= n; i++)
        {
            bool b = false;
            int tmp = i;
            while (tmp)
            {
                int t = tmp % 10;
                if (t == 3 || t == 4 || t == 7)
                {
                    b = false;
                    break;
                }
                if (t == 2 || t == 5 || t == 6 || t == 9) b = true;
                tmp /= 10;
            }
            if (b) dp[i] = dp[i - 1] + 1;
            else dp[i] = dp[i - 1];
        }
        return dp[n];
    }
};